package com.utils;

import com.bean.BaseInfo;
import com.bean.User;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;

import java.lang.reflect.Field;

/**
 * @author FatterShadystart
 * @create 2023-02-10 20:26
 */
public class ParamCheckUtil {

    /**
     * 设置 BaseInfo到实体类中
     * @param baseInfo
     * @return
     */
    public static<T> void checkBaseInfoNoPage(T t,BaseInfo baseInfo){

        try {
            Field fieldCreatorId = t.getClass().getDeclaredField(String.valueOf(baseInfo.getCreatorId()));
            Field fieldUpdatorId = t.getClass().getDeclaredField(String.valueOf(baseInfo.getUpdatorId()));
            fieldCreatorId.setAccessible(true);
            fieldCreatorId.set(t, fieldValue);
        } catch (NoSuchFieldException | IllegalAccessException e) {
            e.printStackTrace();
        }
       t.
    }

    /**
     * 参数检查 BaseInfo不含分页参数
     * @param baseInfo
     * @return
     */
    public static boolean checkBaseInfoNoPage(BaseInfo baseInfo){
        if (ObjectUtils.isEmpty(baseInfo.getCreatorId())){
            return false;
        }
        if (ObjectUtils.isEmpty(baseInfo.getUpdatorId())){
            return false;
        }else {
            return true;
        }
    }
    /**
     * 参数检查 BaseInfo含分页参数
     * @param baseInfo
     * @return
     */
    public static boolean checkBaseInfoYesPage(BaseInfo baseInfo){
        if (ObjectUtils.isEmpty(baseInfo)){
            return false;
        }else {
            return true;
        }
    }

    /**
     * 参数检查 用户注册
     * @param user
     * @return
     */
    public static boolean checkUserRegister(User user){
        if (StringUtils.isEmpty(user.getEmail())){
            return false;
        }
        if (StringUtils.isEmpty(user.getPassword())){
            return false;
        }
            return true;
    }


}
